﻿DROP TRIGGER IF EXISTS  `pk_pack_log`;
CREATE  TRIGGER `pk_pack_log` AFTER INSERT ON `open_pack`
  FOR EACH ROW BEGIN
DECLARE pkf varchar(50) DEFAULT "";
SELECT pk_from INTO pkf FROM open_pk_log WHERE pk_from="pack";
if pkf <> "pack" then
  INSERT INTO open_pk_log SET pk_from = 'pack', pk_id = NEW.pack_id;
eLSE
   update open_pk_log SET pk_id = NEW.pack_id WHERE pk_from = 'pack';
end if;
end;